package com.cyl.manager.pms.domain.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cyl.manager.pms.domain.entity.Brand;
import com.cyl.manager.pms.domain.service.BrandDomainService;
import com.cyl.manager.pms.mapper.BrandMapper;
import com.cyl.manager.pms.req.BrandQueryReq;
import com.sincere.common.utils.StringUtils;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * @author: lsh
 * @create: 2025-01-22 14:50
 **/
@Service
public class BrandDomainServiceImpl extends ServiceImpl<BrandMapper, Brand> implements BrandDomainService {

    private final BrandMapper brandMapper;

    public BrandDomainServiceImpl(BrandMapper brandMapper) {
        this.brandMapper = brandMapper;
    }

    @Override
    public List<Brand> listByPage(BrandQueryReq query, Pageable page) {
        QueryWrapper<Brand> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(StringUtils.isNotEmpty(query.getNameLike()),Brand.COL_NAME, query.getNameLike());
        queryWrapper.eq(Objects.nonNull(query.getSort()),Brand.COL_SORT, query.getSort());
        queryWrapper.eq(Objects.nonNull(query.getShowStatus()),Brand.COL_SHOW_STATUS, query.getShowStatus());
        queryWrapper.eq(StringUtils.isNotEmpty(query.getLogo()),Brand.COL_LOGO, query.getLogo());
        queryWrapper.orderByAsc("sort");
        return brandMapper.selectList(queryWrapper);
    }

    @Override
    public List<Brand> findAllBySortAsc() {
        QueryWrapper<Brand> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByAsc(Brand.COL_SORT);
        return brandMapper.selectList(queryWrapper);
    }
}
